import React, { Component } from 'react'
import { nanoid } from 'nanoid'
import './index.css'

export default class Header extends Component {
  // 键盘回车回调
  handleKeyUp = (e) => {
    if (e.key === 'Enter') {
      const todo = { id: nanoid(), name: e.target.value, done: false }
      this.props.add(todo)
    }
  }
  render() {
    return (
      <div className="header">
        <input onKeyUp={this.handleKeyUp} type="text" placeholder="请输入任务名称" />
      </div>
    )
  }
}
